"""author: songzhiqiang
   data: 2021/11/18
   project: 2021-10-28-弹珠游戏
"""
#需求分析
#1、登陆注册模块
#     欢迎进入三乐购物系统
#     1.登陆
#       需要用户名和密码
#       登陆成功就跳转到购物菜单
#     2.注册
#       需要用户名和密码
#       注册成功就回到登陆初始界面
#2、购物模块
#   1.充值
#   2.选择购买商品
#      查看商品列表
#      选购商品 --  检测余额是否充足
#   3.查看购物车
#      查看购物车列表
#   4.结算
user_dict = {"root":{"passwd":"123456","money":0},
             "admin":{"passwd":"admin","moeny":0}
             }

product_list = {'F00001': {'name':'苹果', 'price':1.2},
                'F00002': {'name':'香蕉', 'price':5.5} }


def check_login(username, passwd):
    if username in user_dict and passwd == user_dict[username]["passwd"]:
        return True
    return False

def register(username, passwd):
    if username not in user_dict:
        user_dict[username] = {"passwd":passwd,"money":0}
        return True
    return False

def  menu():
    print("登陆成功，进入购物".center(30," "))
    print("1.充值    ".center(30," "))
    print("2.选择购买商品".center(30," "))
    print("3.查看购物车 ".center(30," "))
    print("4.结算    ".center(30, " "))

def show_product():
    pass

print(f"欢迎进入三乐购物系统".center(30,"*"))
while True:
    print(f"1.登陆".center(30, " "))
    print(f"2.注册".center(30, " "))
    option = input("请输入你的选择:")
    if option == "1":
        username = input("请输入用户名:")
        passwd = input("请输入密码:")
        if check_login(username, passwd):
            while True:
                menu()
                option1 = input("请输入你的选择:")
                if option1 == "1":
                    money = input("请输入充值金额:")
                    user_dict[username]["money"] += int(money)
                    print(f"当前用户余额为：{user_dict[username]['money']}")
                elif option1 == "2":
                    pass

        else:
            print("登陆失败！")
    elif option == "2":
        username = input("请输入用户名:")
        passwd = input("请输入密码:")
        if register(username, passwd):
            print("注册成功！")
            print(user_dict)
        else:
            print("注册失败！")
    elif option == "exit":
        break
    else:
        print("输入错误，请重新输入")